/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package transervfx.Dato.Entidad;

import java.io.Serializable;
import java.util.ArrayList;
import javafx.beans.property.adapter.JavaBeanProperty;
import javafx.beans.property.adapter.JavaBeanStringProperty;
import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import transervfx.Dato.Validacion.ValidacionesNivelLogico;

/**
 *
 * @author oscar
 */
@NamedQueries({
    @NamedQuery( name = "Agencia.findAll", query = "SELECT a FROM Agencia a"),
    @NamedQuery( name = "Agencia.count", query = "SELECT COUNT(a) FROM Agencia a "),
    @NamedQuery( name = "Agencia.findByNombre", query = "SELECT a FROM Agencia a WHERE a.nombre = :nombre"),
    @NamedQuery( name = "Agencia.findByEmail", query = "SELECT a FROM Agencia a WHERE a.email = :email"),
    @NamedQuery( name = "Agencia.findByCondicionFrenteIVA", query = "SELECT a FROM Agencia a WHERE a.condicionFrenteIVA = :condicionFrenteIVA"),
    @NamedQuery( name = "Agencia.findByCuit", query = "SELECT a FROM Agencia a WHERE a.cuit = :cuit"),
    @NamedQuery( name = "Agencia.findByTelFijo1", query = "SELECT a FROM Agencia a WHERE a.telFijo1 = :telFijo1"),
    @NamedQuery( name = "Agencia.findByTelFijo2", query = "SELECT a FROM Agencia a WHERE a.telFijo2 = :telFijo2"),
    @NamedQuery( name = "Agencia.findByTelCelular1", query = "SELECT a FROM Agencia a WHERE a.telCelular1 = :telCelular1"),
    @NamedQuery( name = "Agencia.findByTelCelular2", query = "SELECT a FROM Agencia a WHERE a.telCelular2 = :telCelular2")
})
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "AGENCIA_TIPO")
public abstract class Agencia implements Serializable {

    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull(message = "* No puede ser nulo", groups = ValidacionesNivelLogico.class)
    @NotEmpty(message = "* Debe completarlo", groups = ValidacionesNivelLogico.class)
    @Size(min = 4, max = 12, message = "* 4 letras minimos, 12 maximo", groups = ValidacionesNivelLogico.class)
    private String nombre;
    @Pattern(regexp = "([a-z][\\w.-]+@\\w[\\w.-]+\\.[\\w.-]*[a-z][a-z])?",message = "* Fomato incorrecto", groups = ValidacionesNivelLogico.class)
    private String email;
    @NotNull(message = "* No puede ser nulo", groups = ValidacionesNivelLogico.class)
    @NotEmpty(message = "* Debe completarlo", groups = ValidacionesNivelLogico.class)
    @Size(min = 4, max = 30, message = "4 letras minimos, 12 maximo", groups = ValidacionesNivelLogico.class)
    private String condicionFrenteIVA;
    @NotNull(message = "* No puede ser nulo", groups = ValidacionesNivelLogico.class)
    @NotEmpty(message = "* Debe completarlo", groups = ValidacionesNivelLogico.class)
    @Pattern(regexp="^[\\d]{2}-[\\d]{7,8}-[\\d]$", message = "* Formato incorrecto\n ejemplo: 29-29895487-9", groups = ValidacionesNivelLogico.class)
    private String cuit;
       
    @Pattern(regexp="([0-9]{2,3}-[0-9]{6,7})?", message = "* Formato incorrecto\n ejemplo: 342-4894507 (cod de area sin 0 de inicio, celular sin 15 de inicio", groups = ValidacionesNivelLogico.class)
    private String telFijo1;
       
    @Pattern(regexp="([0-9]{2,3}-[0-9]{6,7})?", message = " Formato incorrecto\n ejemplo: 342-4894507 (area sin 0 de inicio, celular sin 15 de inicio", groups = ValidacionesNivelLogico.class)
    private String telFijo2;
          
     @Pattern(regexp="([0-9]{2,3}-[0-9]{6,7})?", message = "* Formato incorrecto\n ejemplo: 342-4894507 (area sin 0 de inicio, celular sin 15 de inicio", groups = ValidacionesNivelLogico.class)
    private String telCelular1;
          
    @Pattern(regexp="([0-9]{2,3}-[0-9]{6,7})?", message = "* Formato incorrecto\n ejemplo: 342-4894507 (area sin 0 de inicio, celular sin 15 de inicio", groups = ValidacionesNivelLogico.class)
    private String telCelular2;
            @NotNull(message = "no puede ser nulo", groups = ValidacionesNivelLogico.class)
    @OneToOne(cascade = CascadeType.ALL)
    private Domicilio domicilio;
            
            

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCondicionFrenteIVA() {
        return condicionFrenteIVA;
    }

    public void setCondicionFrenteIVA(String condicionFrenteIVA) {
        this.condicionFrenteIVA = condicionFrenteIVA;
    }

    public String getCuit() {
        return cuit;
    }

    public void setCuit(String cuit) {
        this.cuit = cuit;
    }

    public String getTelFijo1() {
        return telFijo1;
    }

    public void setTelFijo1(String telFijo1) {
        this.telFijo1 = telFijo1;
    }

    public String getTelFijo2() {
        return telFijo2;
    }

    public void setTelFijo2(String telFijo2) {
        this.telFijo2 = telFijo2;
    }

    public String getTelCelular1() {
        return telCelular1;
    }

    public void setTelCelular1(String telCelular1) {
        this.telCelular1 = telCelular1;
    }

    public String getTelCelular2() {
        return telCelular2;
    }

    public void setTelCelular2(String telCelular2) {
        this.telCelular2 = telCelular2;
    }

    public Domicilio getDomicilio() {
        return domicilio;
    }

    public void setDomicilio(Domicilio domicilio) {
        this.domicilio = domicilio;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Agencia)) {
            return false;
        }
        Agencia other = (Agencia) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.nombre;
    }
    //--------------------------------------
    //BINDING
    @Transient
    private JavaBeanStringProperty PROP_NOMBRE;
    @Transient
    private JavaBeanStringProperty PROP_EMAIL;
    @Transient
    private JavaBeanStringProperty PROP_CONDICIONFRENTEIVA;
    @Transient
    private JavaBeanStringProperty PROP_CUIT;
    @Transient
    private JavaBeanStringProperty PROP_TELFIJO1;
    @Transient
    private JavaBeanStringProperty PROP_TELFIJO2;
    @Transient
    private JavaBeanStringProperty PROP_TELCELULAR1;
    @Transient
    private JavaBeanStringProperty PROP_TELCELULAR2;
    @Transient
    private ArrayList<JavaBeanProperty> GroupBindProperties = new ArrayList<JavaBeanProperty>();

    //----------------------CODIGO BINDING
    public JavaBeanStringProperty getPROP_NOMBRE() throws NoSuchMethodException {
        if (PROP_NOMBRE == null) {
            PROP_NOMBRE = JavaBeanStringPropertyBuilder.create().bean(this).name("nombre").build();
            GroupBindProperties.add(PROP_NOMBRE);
        }
        return PROP_NOMBRE;
    }

    public JavaBeanStringProperty getPROP_EMAIL() throws NoSuchMethodException {

        if (PROP_EMAIL == null) {
            PROP_EMAIL = JavaBeanStringPropertyBuilder.create().bean(this).name("email").build();
            GroupBindProperties.add(PROP_EMAIL);
        }
        return PROP_EMAIL;
    }

    public JavaBeanStringProperty getPROP_CONDICIONFRENTEIVA() throws NoSuchMethodException {
        if (PROP_CONDICIONFRENTEIVA == null) {
            PROP_CONDICIONFRENTEIVA = JavaBeanStringPropertyBuilder.create().bean(this).name("condicionFrenteIVA").build();
            GroupBindProperties.add(PROP_CONDICIONFRENTEIVA);
        }
        return PROP_CONDICIONFRENTEIVA;
    }

    public JavaBeanStringProperty getPROP_CUIT() throws NoSuchMethodException {

        if (PROP_CUIT == null) {
            PROP_CUIT = JavaBeanStringPropertyBuilder.create().bean(this).name("cuit").build();
            GroupBindProperties.add(PROP_CUIT);
        }
        return PROP_CUIT;
    }

    public JavaBeanStringProperty getPROP_TELFIJO1() throws NoSuchMethodException {

        if (PROP_TELFIJO1 == null) {
            PROP_TELFIJO1 = JavaBeanStringPropertyBuilder.create().bean(this).name("telFijo1").build();
            GroupBindProperties.add(PROP_TELFIJO1);
        }
        return PROP_TELFIJO1;
    }

    public JavaBeanStringProperty getPROP_TELFIJO2() throws NoSuchMethodException {

        if (PROP_TELFIJO2 == null) {
            PROP_TELFIJO2 = JavaBeanStringPropertyBuilder.create().bean(this).name("telFijo2").build();
            GroupBindProperties.add(PROP_TELFIJO2);
        }
        return PROP_TELFIJO2;
    }

    public JavaBeanStringProperty getPROP_TELCELULAR1() throws NoSuchMethodException {

        if (PROP_TELCELULAR1 == null) {
            PROP_TELCELULAR1 = JavaBeanStringPropertyBuilder.create().bean(this).name("telCelular1").build();
            GroupBindProperties.add(PROP_TELCELULAR1);
        }
        return PROP_TELCELULAR1;
    }

    public JavaBeanStringProperty getPROP_TELCELULAR2() throws NoSuchMethodException {

        if (PROP_TELCELULAR2 == null) {
            PROP_TELCELULAR2 = JavaBeanStringPropertyBuilder.create().bean(this).name("telCelular2").build();
            GroupBindProperties.add(PROP_TELCELULAR2);
        }
        return PROP_TELCELULAR2;
    }

    public void unbindingALL() {
        for (JavaBeanProperty beanBinding : GroupBindProperties) {
            beanBinding.unbind();
        }
    }
}
